package com.itheima.service;


import com.itheima.domain.Student;
import com.itheima.mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class StudentServiceTest {
    private StudentMapper dao;
    private SqlSession sqlSession;

    @Before
    public void init()throws Exception{
        //加载核心配置文件
        InputStream is = Resources.getResourceAsStream("MybatisConfig.xml");
        //获取factory工厂对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //获取sqlsession对象
        sqlSession = factory.openSession();
        //获取dao代理对象
        dao=sqlSession.getMapper(StudentMapper.class);

    }

  @After
  public void destroy(){

      //释放资源
      sqlSession.close();
  }



    @Test
    public void findAll(){
        List<Student> students = dao.findAll();
        for (Student student : students) {
            System.out.println(student);
        }
    }





}
